package Controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Serializable;

import Communication.Client;
import Controller.PatternController.NewPatternListener;
import Entity.Pattern;
import HandleDB.PatternQuery;
import Communication.Client;
import HandleDB.PatternQuery;
import View.*;
//import View.NewProductToCatalogView;

public class PatternController implements Serializable {
	private static final long serialVersionUID = 1L;
	PatternConfigView patternView;
	Client client;
	PatternQuery patternModel;
	
	public PatternController (Client client, WorkerMainMenuController workerMainMenuController) {
		this.client = client;
		patternView = new PatternConfigView();
		patternView.showWindow();
		patternView.PatternConfigListener(new NewPatternListener(workerMainMenuController));
	}
	
	
	
	class NewPatternListener implements ActionListener
	{
		WorkerMainMenuController workerMainMenuController;
		
		public  NewPatternListener(WorkerMainMenuController workerMainMenuController){
			this.workerMainMenuController = workerMainMenuController;
			patternModel = new PatternQuery(client);
			//patternView.showWindow();
		}
	
		public void actionPerformed(ActionEvent event) {
			
			
			if (event.getSource() == patternView.getSubmitButton())
			{
				if (patternModel.isEmpty(patternView.getProductName()) || (patternView.getAge()==null) ||patternModel.isEmpty(patternView.getCustomerCity())  
						||patternModel.isEmpty(patternView.getCustomerImportance()) || patternModel.isEmpty(patternView.getCustomerInteresting())
								||patternModel.isEmpty(patternView.getCustomerPermission()) ||patternModel.isEmpty(patternView.getMassageToCustomer()))
					SystemController.displayErrorMessage("One or more fields are Empty");
				
				else
				{ 
					SystemController.displayMessage("Pattern Added successfully !");
					patternView.showWindow();
					workerMainMenuController.hideWindow();
					patternView.clearFields();
					
				}
			}
			else if (event.getSource() == patternView.getBackButton())
			{
				workerMainMenuController.showWindow();
				patternView.hideWindow();
				//workerMainMenuController.hideWindow();
				patternView.clearFields();
			}
			
			
		}	
		}
	
}
